import wepy from 'wepy';

// import tip from '@/utils/tip';

const wxRequest = async (params = {}, url) => {
  typeof params.tipStart === 'function' && params.tipStart();

  let data = params.query || {};
  let content = params.header || 'application/json';

  let res = await wepy.request({ //await 以下的代码会被阻止,直到Promise中的代码执行完
    url: url,
    method: params.method || 'GET',
    data: data,
    header: { 'content-type': content }
  });

  typeof params.tipEnd === 'function' && params.tipEnd();
  return res;
};

const wxUploadFile = async (params = {}, url) => {
  let data = params.query || {};
  let res = await wepy.uploadFile({
    url: url,
    name: params.name,
    formData: data,
    filePath: params.filePath
  })
  return res;
}


module.exports = {
  wxRequest,
  wxUploadFile
}
